package com.xdxc.service.factory;

import com.xdxc.exception.CustomException;
import com.xdxc.service.strategy.QuestionTypeStrategy;
import com.xdxc.service.strategy.impl.MultiChoiceStrategy;
import com.xdxc.service.strategy.impl.ShortStrategy;
import com.xdxc.service.strategy.impl.SingleChoiceStrategy;
import com.xdxc.service.strategy.impl.TrueFalseStrategy;
import org.springframework.stereotype.Component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class QuestionTypeStrategyFactory {
    private final ApplicationContext context;

    @Autowired
    public QuestionTypeStrategyFactory(ApplicationContext context) {
        this.context = context;
    }

    public QuestionTypeStrategy getStrategy(int quType) {
        return switch (quType) {
            case 1 -> context.getBean(SingleChoiceStrategy.class);
            case 2 -> context.getBean(MultiChoiceStrategy.class);
            case 3 -> context.getBean(TrueFalseStrategy.class);
            case 4 -> context.getBean(ShortStrategy.class);
            default -> throw new CustomException(400, "Unknown question type");
        };
    }
}